
<SCRIPT language=javascript>
function Checklogin()
{
	if (document.getElementById(stu_num)=="")
	{
		alert("用户名不能为空");
		myform.stu_num.focus();
		return false;
	}
		if (document.getElementById(stu_psw)=="")
	{
		alert("密码不能为空");
		myform.stu_psw.focus();
		return false;
	}
}
</SCRIPT>

<form name="myform" action="" method="post"
	onsubmit="return Checklogin();">
	<table border="0" cellspacing="5">
		<tr>
			<th align="right">
				学号
			</th>
			<td align="left">
				<input type="text" id="stu_num" name="stu_num">
			</td>
		</tr>
		<tr>
			<th align="right">
				密码
			</th>
			<td align="left">
				<input type="password" id="stu_psw" name="stu_psw">
			</td>
		</tr>
		<tr>
			<td align="right">
				<input type="submit" name="submit" value="提交">
			</td>
			<td align="left">
				<input type="reset" value="重置">
			</td>
		</tr>
	</table>
</form>

<?php
include ("global.php");


if($_POST[submit])
{
	$stu_psw = $_REQUEST["stu_psw"];
	$stu_num = $_REQUEST["stu_num"];
	$sql = "select * from `stu_data` where `stu_num`=$stu_num";
	$result = $db->query($sql);
	$row = mysql_fetch_array($result);
	$stu_name = $row['stu_name'];
	setcookie("stu_name","$stu_name",time()+3600);
	if (($row['stu_psw'] == $stu_psw) && $stu_num != null) {

		echo "<script language=javascript>";
		echo " alert(\"点击确定跳转\");";
		if ($stu_num == "0") {
			echo "top.location='admin.php' ;";
		} else {
			echo "top.location='submit.php';";
		}
		echo "</script>";


	} else {
		echo "<script language=javascript>";

		echo " alert(\"登陆错误!\");";
		echo "</script>";
	}
}

?>